package javolution.testing;

import javolution.context.LogContext;
import javolution.context.ObjectFactory;
import javolution.text.TextBuilder;

/* loaded from: classes2.dex */
public abstract class TestContext extends LogContext {
    public static final Class<TestContext> REGRESSION = Regression.CLASS;
    private static final Boolean TRUE = new Boolean(true);
    private static final Boolean FALSE = new Boolean(false);

    /* loaded from: classes2.dex */
    private static final class Regression extends TestContext {
        private static final Class CLASS = new Regression().getClass();

        private Regression() {
        }

        @Override // javolution.testing.TestContext
        public boolean doAssertEquals(String str, Object obj, Object obj2) {
            if ((obj != null || obj2 == null) && (obj == null || obj.equals(obj2))) {
                return true;
            }
            throw new AssertionException(str, obj, obj2);
        }

        @Override // javolution.testing.TestContext
        public void doTest(TestCase testCase) {
            testCase.prepare();
            try {
                testCase.execute();
                testCase.validate();
            } finally {
                testCase.cleanup();
            }
        }

        @Override // javolution.context.LogContext
        public boolean isErrorLogged() {
            return false;
        }

        @Override // javolution.context.LogContext
        public boolean isInfoLogged() {
            return false;
        }

        @Override // javolution.context.LogContext
        public boolean isWarningLogged() {
            return false;
        }

        @Override // javolution.context.LogContext
        public void logError(Throwable th, CharSequence charSequence) {
        }

        @Override // javolution.context.LogContext
        public void logInfo(CharSequence charSequence) {
        }

        @Override // javolution.context.LogContext
        public void logWarning(CharSequence charSequence) {
        }
    }

    static {
        ObjectFactory.setInstance(new ObjectFactory() { // from class: javolution.testing.TestContext.1
            /* JADX INFO: Access modifiers changed from: protected */
            @Override // javolution.context.ObjectFactory
            public Object create() {
                return new Regression();
            }
        }, Regression.CLASS);
    }

    public static boolean assertEquals(Object obj, Object obj2) {
        return assertEquals(null, obj, obj2);
    }

    public static boolean assertEquals(String str, Object obj, Object obj2) {
        LogContext current = LogContext.getCurrent();
        if (current instanceof TestContext) {
            return ((TestContext) current).doAssertEquals(str, obj, obj2);
        }
        if ((obj != null || obj2 == null) && (obj == null || obj.equals(obj2))) {
            return true;
        }
        if (current.isErrorLogged()) {
            TextBuilder newInstance = TextBuilder.newInstance();
            if (str != null) {
                newInstance.append(str).append(": ");
            }
            newInstance.append(obj);
            newInstance.append(" expected but found ");
            newInstance.append(obj2);
            current.logError((Throwable) null, newInstance);
            TextBuilder.recycle(newInstance);
            return false;
        }
        return false;
    }

    public static boolean assertTrue(String str, boolean z) {
        Boolean bool = TRUE;
        return assertEquals(str, bool, z ? bool : FALSE);
    }

    public static boolean assertTrue(boolean z) {
        Boolean bool = TRUE;
        return assertEquals(null, bool, z ? bool : FALSE);
    }

    public static void test(TestCase testCase) {
        LogContext current = LogContext.getCurrent();
        if (current instanceof TestContext) {
            ((TestContext) current).doTest(testCase);
            return;
        }
        if (current.isInfoLogged()) {
            current.logInfo(testCase.toString());
        }
        testCase.prepare();
        try {
            testCase.execute();
            testCase.validate();
        } finally {
            testCase.cleanup();
        }
    }

    public abstract boolean doAssertEquals(String str, Object obj, Object obj2);

    public abstract void doTest(TestCase testCase);
}
